package com.jyw.business.ins.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jyw.business.ins.domain.InsPlanSkip;
import com.jyw.business.ins.domain.model.CreateTaskTimeRage;
import com.jyw.business.ins.mapper.InsPlanSkipMapper;
import com.jyw.business.ins.service.IInsPlanSkipService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 巡检计划跳过任务储存Service业务层处理
 *
 * @author zhangcheng
 * @date 2023-12-25
 */
@Service
public class InsPlanSkipServiceImpl extends ServiceImpl<InsPlanSkipMapper, InsPlanSkip> implements IInsPlanSkipService {

    @Override
    public void saveSkipTask(Long planId, LocalDate skipDate, Integer skipType,List<CreateTaskTimeRage> timeRages) {
        InsPlanSkip insPlanSkip=new InsPlanSkip();
        insPlanSkip.setPlanId(planId);
        insPlanSkip.setSkipDate(skipDate);
        insPlanSkip.setSkipType(skipType);
        insPlanSkip.setCreateTime(LocalDateTime.now());
        if(CollUtil.isNotEmpty(timeRages)){
            String skipTask=JSONArray.toJSONString(timeRages);
            insPlanSkip.setSkipTask(skipTask);
        }
        this.save(insPlanSkip);
    }

    @Override
    public void deleteSkipTask(Long planId, LocalDate skipDate) {
        this.baseMapper.deleteSkipTask(planId,skipDate);
    }

    @Override
    public List<InsPlanSkip> findSkipTask(Long planId, LocalDate skipDate) {
        return this.baseMapper.findSkipTask(planId, skipDate);
    }
}
